package com.xzmzhp.dao.people;

import com.xzmzhp.dao.people.SQL.SocietySQL;
import com.xzmzhp.pojo.people.Society;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author 王源
 * @Date: 2020/11/15 19:59
 * @Description: 社团数据库操作类
 */
@Repository
public interface SocietyMapper {

    /**
     * 查询所有社团
     *
     * @return list对象
     */
    @Select("select society_id,society_name,society_school from society")
    List<Society> findAll();

    /**
     * 根据社团名称模糊查询社团信息
     *
     * @param societyName 社团名称
     * @return list对象
     */
    @Select("select society_id,society_name,society_school from society where society_name COLLATE utf8_general_ci like '%${societyName}%'")
    List<Society> findBySocietyName(@Param("societyName") String societyName);

    /**
     * 根据学校名称模糊查询社团信息
     *
     * @param societySchool 学校名称
     * @return list对象
     */
    @Select("select society_id,society_name,society_school from society where society_school like '%${societySchool}%'")
    List<Society> findBySocialSchool(@Param("societySchool") String societySchool);

    /**
     * 根据学校名称和社团名称模糊查询
     *
     * @param societyName  社团名称
     * @param societySchool 学校名称
     * @return list对象
     */
    @SelectProvider(type = SocietySQL.class, method = "findBySocial")
    List<Society> findBySocial(@Param("societyName") String societyName, @Param("societySchool") String societySchool);

    /**
     * 根据社团id查询社团名称
     *
     * @param societyId 社团id
     * @return Society对象
     */
    @Select("select society_id,society_name,society_school from society where society_id=#{societyId}")
    Society findBySocialId(@Param("societyId") Integer societyId);

    /**
     * 添加社团
     *
     * @param society 社团对象
     * @return Integer
     */
    @Insert("insert into society values(null,#{societyName},#{societySchool},null,null)")
    Integer addSociety(Society society);

    /**
     * 修改社团信息
     *
     * @param society 社团实体类
     * @return Integer
     */
    @UpdateProvider(type = SocietySQL.class, method = "updateSocial")
    Integer updateSociety(Society society);

    /**
     * 删除社团
     *
     * @param societyId 社团id
     * @return Integer
     */
    @Delete("delete from society where society_id=#{societyId}")
    Integer deleteSociety(@Param("societyId") Integer societyId);
}
